package com.tedu.openmedical.medicalsystem.fqa.controller;

import com.tedu.openmedical.base.response.JsonResult;
import com.tedu.openmedical.medicalsystem.fqa.dto.FAQQuery;
import com.tedu.openmedical.medicalsystem.fqa.dto.FAQSaveParam;
import com.tedu.openmedical.medicalsystem.fqa.service.FAQService;
import com.tedu.openmedical.medicalsystem.fqa.vo.FAQVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping("/v1/faq/")
@Slf4j
@Api(tags = "FAQ管理")
public class FAQController {

    @Autowired
    private FAQService faqService;

    @GetMapping("select")
    @ApiOperation(value = "查询FAQ列表", notes = "查询FAQ列表")
    public JsonResult select(FAQQuery query) {
        log.debug("查询FAQ列表:{}", query);
        List<FAQVO> faqvoList =  faqService.select(query);
        return JsonResult.ok(faqvoList);
    }

    @PostMapping("save")
    @ApiOperation(value = "保存FAQ", notes = "保存FAQ")
    public JsonResult save(FAQSaveParam faqSaveParam) {
        log.debug("保存FAQ:{}", faqSaveParam);
        faqService.save(faqSaveParam);
        return JsonResult.ok();
    }

    @GetMapping("delete")
    @ApiOperation(value = "删除FAQ", notes = "删除FAQ")
    public JsonResult delete(Long id) {
        log.debug("删除FAQ:{}", id);
        faqService.delete(id);
        return JsonResult.ok();
    }
}
